package com.mchsdk.paysdk.http.process;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.entity.StringEntity;

import com.lidroid.xutils.http.RequestParams;
import com.mchsdk.paysdk.bean.ChannelAndGameInfo;
import com.mchsdk.paysdk.bean.PersonalCenterModel;
import com.mchsdk.paysdk.config.MCHConstant;
import com.mchsdk.paysdk.http.request.ChangePasswordRequest;
import com.mchsdk.paysdk.utils.MCLog;
import com.mchsdk.paysdk.utils.RequestParamUtil;

import android.os.Handler;

public class ChangePasswordProcess {

	private static final String TAG = "ChangePasswordProcess";

	private String code;
	private String pwd;
	private String repwd;

	/**
	 * 修改密码请求需要的参数
	 * @return 返回一个String
	 */
	private String getParamStr(){
		Map<String, String> map = new HashMap<String, String>();
		map.put("account", PersonalCenterModel.getInstance().getAccount());
		map.put("user_id", PersonalCenterModel.getInstance().getUserId());
		map.put("game_id", ChannelAndGameInfo.getInstance().getGameId());
		map.put("password", repwd);
		map.put("code", code);
		map.put("old_password", pwd);
		MCLog.w(TAG, "fun#ptb_pay params:" + map.toString());
		
		return RequestParamUtil.getRequestParamString(map);
	}

	/**
	 * 掉用此方法启动请求
	 * @param handler 请求后用到
	 */
	public void post(Handler handler) {
		RequestParams params = new RequestParams();
		try {
			params.setBodyEntity(new StringEntity(getParamStr().toString()));
		} catch (UnsupportedEncodingException e) {
			params = null;
			MCLog.e(TAG, "fun#post UnsupportedEncodingException:" + e);
		}

		if (null != handler && null != params) {
			ChangePasswordRequest request = new ChangePasswordRequest(handler);
			request.post(MCHConstant.getInstance().getUpdateUserInfoUrl(),
					params);
		} else {
			MCLog.e(TAG, "fun#post handler is null or url is null");
		}
	}

	public void setCode(String code) {
		this.code = code;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public void setRepwd(String repwd) {
		this.repwd = repwd;
	}
	
}
